package com.eastmoney.emis.edda.controller.inner;

import com.eastmoney.emis.edda.domain.valueobject.TimeFormatter;
import com.eastmoney.emis.edda.infrastructure.report.ReportType;
import com.eastmoney.emis.edda.infrastructure.report.service.ReportFileService;
import com.eastmoney.emis.edda.infrastructure.report.service.ReportService;
import com.eastmoney.emis.edda.infrastructure.report.service.ReportServiceImpl;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * @description: Description
 * @projectName: EDDA-HSBC
 * @package: com.eastmoney.emis.edda.controller.inner
 * @author: 汪程程
 * @date: 2022/11/3 10:47 AM
 * @version: 1.0
 */
@RestController
@RequestMapping("/innerApi/hsbc")
public class ReportController {

    @Autowired
    private ReportFileService reportFileService;

    @Autowired
    private ReportService reportService;

    @ApiOperation("HSBC eDDA/eDDI report接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportType", value = "报告类型: dda / ddi ", required = true),
            @ApiImplicitParam(name = "date", value = "日期: 2022-11-03 ", required = true),
    })
    @GetMapping("/reports/{reportType}/{date}")
    public String report(@PathVariable("reportType") String reportTypeStr, @PathVariable("date") String date) {
        return reportFileService.findDownloadPath(date, ReportType.parse(reportTypeStr));
    }

    @ApiOperation("HSBC eDDA/eDDI report 重试接口 - 会请求汇丰服务，重新拉取")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportType", value = "报告类型: dda / ddi ", required = true),
            @ApiImplicitParam(name = "date", value = "日期: 2022-11-03 ", required = true),
    })
    @PostMapping("/reports/{reportType}/{date}")
    public void eddaReport(@PathVariable("reportType") String type, @PathVariable("date") String date) throws Exception {
        ReportType reportType = ReportType.parse(type);
        LocalDate reportDate = LocalDate.parse(date, TimeFormatter.YYYY_MM_DD);
        if(reportType == ReportType.DDAReport) {
            reportService.processEddaReport(reportDate);
        }
        if(reportType == ReportType.DDIReport) {
            reportService.processEddiReport(reportDate);
        }

    }
}
